package com.ruoyi.web.controller.business.goods;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.goods.domain.JbCropGrowthPeriod;
import com.ruoyi.business.goods.service.JbCropGrowthPeriodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作物生育期 Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("作物生育期")
@RestController
@RequestMapping("/crop_growth_period")
public class JbCropGrowthPeriodController extends BaseController
{
    @Autowired
    private JbCropGrowthPeriodService service;

    /**
     * 查询作物生育期列表
     */
    @ApiOperation("查询作物生育期列表")
    @PreAuthorize("@ss.hasPermi('crop_growth_period:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbCropGrowthPeriod jbCropGrowthPeriod)
    {
        startPage();
        LambdaQueryWrapper<JbCropGrowthPeriod> select = new LambdaQueryWrapper<>();
        IPage<JbCropGrowthPeriod> iPage = service.page(page.b(), select);
        return getDataTable(iPage.getRecords());
    }

    /**
     * 导出作物生育期列表
     */
    @ApiOperation("导出作物生育期列表")
    @PreAuthorize("@ss.hasPermi('crop_growth_period:export')")
    @Log(title = "作物生育期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageParam page, JbCropGrowthPeriod jbCropGrowthPeriod)
    {
        LambdaQueryWrapper<JbCropGrowthPeriod> select = new LambdaQueryWrapper<>();
        IPage<JbCropGrowthPeriod> iPage = service.page(page.b(), select);

        List<JbCropGrowthPeriod> list = iPage.getRecords();
        ExcelUtil<JbCropGrowthPeriod> util = new ExcelUtil<JbCropGrowthPeriod>(JbCropGrowthPeriod.class);
        util.exportExcel(response, list, "作物生育期数据");
    }

    /**
     * 获取作物生育期详细信息
     */
    @ApiOperation("获取作物生育期详细信息")
    @PreAuthorize("@ss.hasPermi('crop_growth_period:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }

    /**
     * 新增作物生育期
     */
    @ApiOperation("新增作物生育期")
    @PreAuthorize("@ss.hasPermi('crop_growth_period:add')")
    @Log(title = "作物生育期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbCropGrowthPeriod jbCropGrowthPeriod)
    {
        return toAjax(service.save(jbCropGrowthPeriod));
    }

    /**
     * 修改作物生育期
     */
    @ApiOperation("修改作物生育期")
    @PreAuthorize("@ss.hasPermi('crop_growth_period:edit')")
    @Log(title = "作物生育期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbCropGrowthPeriod jbCropGrowthPeriod)
    {
        return toAjax(service.updateById(jbCropGrowthPeriod));
    }

    /**
     * 删除作物生育期
     */
    @ApiOperation("删除作物生育期")
    @PreAuthorize("@ss.hasPermi('crop_growth_period:remove')")
    @Log(title = "作物生育期", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.removeByIds(Arrays.asList(ids)));
    }
}
